public class Solution769 {
    public int maxChunksToSorted(int[] arr) {
        if (arr.length==0){
            return 0;
        }
        int[] f=new int[arr.length];
        int[] g=new int[arr.length];
        int ans=1;
        f[0]=arr[0];
        for (int i=1;i<arr.length;i++){
            f[i]=Math.max(f[i-1],arr[i]);
        }
        g[arr.length-1]=arr[arr.length-1];
        for (int i=arr.length-2;i>=0;i--){
            g[i]=Math.min(g[i+1],arr[i]);
        }
        for (int i=0;i<arr.length-1;i++){
            if (f[i]<g[i+1]){
                ans++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution769().maxChunksToSorted(new int[]{0,1,2,3,4}));
    }
}
